/*
 * @Description: 钱包充值账单界面
 * @Author: tao.xie
 * @Date: 2019-03-29 11:38:36
 * @Last Modified by: yingying.fan
 * @Last Modified time: 2019-04-26 16:25:25
 */
<template>
  <route-bill-main
    :info-list="infoList"
    :detail-icon="detailIcon"
    :detail-msg="mallBill.title"
    :price="mallBill.orderPrice"
    :baseIconTheme="!tradeClosed"
  />
</template>

<script>
import Vue from 'vue'
import RouteBillMain from '../components/RouteBillMain'
import { getMallBill } from '../api/api.js'
import { SUCCESS, HALF_FAIL, FAIL, TOPAY, CLOSE } from '../constants/WalletTradeStatus.js'
import { goToOrderDetail } from '@/utils/JumpUtils.js'
import { getUrlParamByKey } from 'vue-xiaobu-utils'
export default {
  components: {
    'route-bill-main': RouteBillMain
  },
  data() {
    return {
      detailIcon: require('../assets/wallet.png'),
      infoList: [],
      mallBill: {}
    }
  },
  computed: {
    tradeClosed() {
      // return this.mallBill.state === FAIL
      switch (this.mallBill.orderStatus) {
        case FAIL:
        case HALF_FAIL:
        case CLOSE:
          return true
      }
      return false
    }
  },
  mounted() {
    this._getMallBill(getUrlParamByKey('tradeno'))
    Vue.$EventBus.$on('look', () => { this.pushToOrderDetail() })
  },
  methods: {
    _getMallBill: async function (tradeno) {
      try {
        this.mallBill = await getMallBill(tradeno)
        let copyinfolist = []
        copyinfolist.push({
          infoName: '支付状态',
          infoValue: this.parsePayResult()
        })
        copyinfolist.push({
          infoName: '订单详情',
          infoValue: '查看',
          isButton: true,
          eventName: 'look'
        })
        if (this.mallBill.payName) {
          copyinfolist.push({
            infoName: '支付方式',
            infoValue: this.mallBill.payName + (this.mallBill.bankCardNo ? ' (' + this.mallBill.bankCardNo + ')' : '')
          })
        }

        copyinfolist.push({
          infoName: '创建时间',
          infoValue: this.mallBill.createTime
        })
        if (this.mallBill.payTime) {
          copyinfolist.push({
            infoName: '支付时间',
            infoValue: this.mallBill.payTime
          })
        }
        copyinfolist.push({
          infoName: '账单编号',
          infoValue: this.mallBill.tradeNo
        })
        this.infoList = copyinfolist
      } catch (err) { }
    },
    parsePayResult() {
      let result
      switch (this.mallBill.orderStatus) {
        case SUCCESS:
          result = '充值成功'
          break
        case FAIL:
        case HALF_FAIL:
          result = '交易关闭'
          break
        case TOPAY:
          result = '待支付'
          break
        case CLOSE:
          result = '交易关闭'
          break
        default:
          result = '交易中'
          break
      }
      return result
    },
    pushToOrderDetail() {
      goToOrderDetail(this.mallBill.orderNo)
    }
  }
}
</script>

<style>
</style>
